{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[1m\u001b[32mave. squared distance = 43.20515185350062\u001b[0m\n"
     ]
    },
    {
     "ename": "AttributeError",
     "evalue": "module 'vedo' has no attribute 'backends'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[1], line 22\u001b[0m\n\u001b[1;32m     19\u001b[0m     d \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m mag2(p \u001b[38;5;241m-\u001b[39m cpt)  \u001b[38;5;66;03m# square of residual distance\u001b[39;00m\n\u001b[1;32m     21\u001b[0m printc(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mave. squared distance =\u001b[39m\u001b[38;5;124m\"\u001b[39m, d \u001b[38;5;241m/\u001b[39m arim\u001b[38;5;241m.\u001b[39mnpoints, c\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mg\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m---> 22\u001b[0m \u001b[43mplt\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mshow\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m~/vedoenv/lib/python3.12/site-packages/vedo/plotter.py:3457\u001b[0m, in \u001b[0;36mPlotter.show\u001b[0;34m(self, at, axes, resetcam, zoom, interactive, viewup, azimuth, elevation, roll, camera, mode, rate, bg, bg2, size, title, screenshot, *objects)\u001b[0m\n\u001b[1;32m   3455\u001b[0m \u001b[38;5;66;03m# 2d ####################################################################\u001b[39;00m\n\u001b[1;32m   3456\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m vedo\u001b[38;5;241m.\u001b[39msettings\u001b[38;5;241m.\u001b[39mdefault_backend \u001b[38;5;129;01min\u001b[39;00m [\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m2d\u001b[39m\u001b[38;5;124m\"\u001b[39m]:\n\u001b[0;32m-> 3457\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mvedo\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbackends\u001b[49m\u001b[38;5;241m.\u001b[39mget_notebook_backend()\n\u001b[1;32m   3458\u001b[0m \u001b[38;5;66;03m#########################################################################\u001b[39;00m\n\u001b[1;32m   3460\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\n",
      "\u001b[0;31mAttributeError\u001b[0m: module 'vedo' has no attribute 'backends'"
     ]
    }
   ],
   "source": [
    "\"\"\"Align 2 shapes: a simple line to a polygonal mesh\"\"\"\n",
    "from vedo import *\n",
    "\n",
    "settings.default_backend = '2d' # or k3d, ipyvtk,trame or vtk\n",
    "\n",
    "limb = Mesh(dataurl + \"270.vtk\").alpha(0.5)\n",
    "rim  = Mesh(dataurl + \"270_rim.vtk\").c(\"red4\").lw(3)\n",
    "\n",
    "# make a clone copy of the rim line and align it to the surface\n",
    "arim = rim.clone().align_to(limb, rigid=True).c(\"g\")\n",
    "\n",
    "plt = Plotter()\n",
    "plt += [limb, rim, arim]\n",
    "\n",
    "# compute how well it fits\n",
    "d = 0\n",
    "for p in arim.vertices:\n",
    "    cpt = limb.closest_point(p)\n",
    "    d += mag2(p - cpt)  # square of residual distance\n",
    "\n",
    "printc(\"ave. squared distance =\", d / arim.npoints, c=\"g\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<tr>\n",
       "<td>\n",
       "<img src=''></img>\n",
       "</td>\n",
       "<td style='text-align: center; vertical-align: center;'><br/>\n",
       "<b><a href=\"https://vedo.embl.es/docs/vedo/mesh.html\" target=\"_blank\">vedo.mesh.Mesh</a></b><br/><code><i>(....embl.es/examples/data/270.vtk)</i></code>\n",
       "<table>\n",
       "<tr><td><b> bounds </b> <br/> (x/y/z) </td><td>4.480 ... 892.7<br/>-570.2 ... 623.1<br/>-513.1 ... 421.8</td></tr>\n",
       "<tr><td><b> center of mass </b></td><td>(375, -3.34, -99.9)</td></tr>\n",
       "<tr><td><b> average size </b></td><td>470.220</td></tr>\n",
       "<tr><td><b> nr. points&nbsp/&nbspfaces </b></td><td>820&nbsp/&nbsp1526</td></tr>\n",
       "\n",
       "\n",
       "</table>\n",
       "</table>"
      ],
      "text/plain": [
       "<vedo.mesh.Mesh at 0x7f545d9ae410>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "limb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Object `vedo` not found.\n"
     ]
    }
   ],
   "source": [
    "?vedo\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'vedo' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[3], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mvedo\u001b[49m\n",
      "\u001b[0;31mNameError\u001b[0m: name 'vedo' is not defined"
     ]
    }
   ],
   "source": [
    "vedo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import vedo.backends\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
